package org.zxl.springbootdemo.springjdbc2.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementSetter;
import org.springframework.stereotype.Component;
import org.zxl.springbootdemo.springjdbc2.entity.ZqhDiary;

@Component
public class ZqhDAO {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    public void insert(ZqhDiary zqhDiary){
        String sql = "insert into zqh_diary (id,name,description) values(?,?,?)";
        PreparedStatementSetter pss = (preparedStatement) -> {
            preparedStatement.setInt(1,zqhDiary.getId());
            preparedStatement.setString(2,zqhDiary.getName());
            preparedStatement.setString(3,zqhDiary.getDescription());
        };
        jdbcTemplate.update(sql, pss);
    }
}
